#include <stdio.h>
#include <unistd.h>
#include <container.h>
#include "tp_config.h"
void ttask1(void *args, thread_task_args_t *ttat){
    thread_pool_t *tpt = ttat->tpt;
    int i=10;
    int j=0;
    while (i){
        j++;
        i--;
    }
    printf("1 -- threads is %d task num is %d waiting num is %d\n", tpt->threads, tpt->queue.count, tpt->waiting);
}
void ttask2(void *args, thread_task_args_t *ttat){
    char* str = (char*)args;
    thread_pool_t *tpt = ttat->tpt;
    int i=10;
    int j=0;
    while (i){
        j++;
        i--;
    }
    printf("2 %s -- threads is %d task num is %d waiting num is %d\n",str, tpt->threads, tpt->queue.count, tpt->waiting);
}
void ttask3(void *args, thread_task_args_t *ttat){
    thread_pool_t *tpt = ttat->tpt;
    long j = 0;
    while(1){
        for (int i = 0; i < 10000; ++i) {
            Thread_Task_Post(tpt, &ttask1, "AA");
        }
        printf("-------------3-1-----------\n");
        j++;
        if(j%20 == 0) {
            sleep(50);
        }
    }


}
void ttask4(void *args, thread_task_args_t *ttat){
    thread_pool_t *tpt = ttat->tpt;
    long j = 0;
    while(1){
        for (int i = 0; i < 100000; ++i) {
            Thread_Task_Post(tpt, &ttask2, "BB");
        }
        printf("-------------4-1-----------\n");
        j++;
        if(j%10 == 0) {
            sleep(50);
        }
    }
}
int main()
{
    setbuf(stdout, NULL);       // 正式使用时请去掉该代码
    thread_pool_t tpt;
    Thread_Pool_Init(&tpt);
    tpt.initthreads = 500;
    tpt.maxthreads = 1000;
    tpt.minthreads = 1;
    Thread_Task_Post(&tpt, &ttask3, NULL);
    Thread_Task_Post(&tpt, &ttask4, NULL);
    Thread_Pool_Commit(&tpt);
    Thread_Pool_Sync();
    return 0;  // Never returns
}

